

use crate::structs::types::{Person, Sex, Color, DAULT_AGE};

impl Person {
    fn new(person: &Person) -> Self {
        Person {
            name: person.name.clone(),
            age: person.age,
            height: person.height,
            sex: Sex::FEMALE,
            active: person.active,
            sign_times: person.sign_times
        }
    }
    fn get_human(&self) {
        println!("person: {:#?}", &self);
    }
    fn is_dault(&self) -> bool {
        let result = self.age >= DAULT_AGE;
        println!("result: {:?}", result);
        return result;
    }
}

/**
 * rust基本语法
*/
pub fn run() {
    // 数字类型
    let a = 1;
    let a = 2;

    println!("a={}", a);

    // 可变数字类型
    let mut b = 3;
    b = 4;
    println!("b = {}", b);

    // 浮点数类型
    let f: f32 = 0.2;
    println!("f = {}", f);

    // 常量
    const MAX_FILE_SIZE: usize = 1024;
    println!("max_file_size: {}", MAX_FILE_SIZE);

    // 布尔类型
    let is_true = false;
    println!("isTrue = {}", is_true);

    // 数组类型
    let mut arr = vec![1,2,3,4,5,6];
    arr.push(7);
    println!("{:?}", arr);

    let (x, y) = (1, 2);
    println!("x: {}, y: {}", x, y);

    // 结构体类型
    let person = Person {
        name: "John".to_owned(),
        age: 17,
        height: 180,
        sex: Sex::FEMALE,
        active: true,
        sign_times: 10
    };

    let p = Person::new(&person);
    p.get_human();
    p.is_dault();

    // 枚举类型
    let color = Color("#000000".to_string(), "#ffffff".to_string());
    println!("color: {:?}", color);
}
